package com.github.mrs.test;

import com.github.mrs.spring.Autowired;
import com.github.mrs.spring.BeanNameAware;
import com.github.mrs.spring.Component;
import com.github.mrs.spring.InitializingBean;

/**
 * date: 2023/9/19 19:11
 * author: MR.孙
 */
@Component("userService")
// @Scope("prototype")
//BeanDefinition 定义bean相关的属性，比如@Component标注的是bean对象，并且beanName为userService。
public class UserService implements InitializingBean, UserInterface, BeanNameAware {

    @Autowired
    private OrderService orderService;

    //现在我们想要bean加载的时候就要有一个默认的用户：mysql->user
    // 也就是在bean加载的时候就需要从mysql中拿到user
    //这里使用spring的扩展接口InitializingBean手动模拟InitializingBean的实现，保证bean加载之后能拿到一个默认用户

    private User defaultUser;

    @MrsValue("123")
    private String str;

   //Bean实例的名字，通过BeanNameAware的setter方法赋值
    private String beanName;

    //初始化
    @Override
    public void afterPropertiesSet() {
        defaultUser = new User();
        // System.out.println("初始化：" + defaultUser );

    }

    public void test() {
        System.out.println(orderService);
        System.out.println(str);
        System.out.println(beanName);

    }

    @Override
    public void setBeanName(String beanName) {
        this.beanName = beanName;
    }
}
